package com.heima.user.controller;

import com.heima.model.common.constants.admin.AdminConstants;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.user.dtos.AuthDto;
import com.heima.model.user.pojos.ApUser;
import com.heima.user.service.ApUserRealService;
import com.heima.user.service.ApUserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/auth")

public class AuthController {
    @Autowired
    private ApUserRealService apUserRealService;
    @Autowired
    private ApUserService apUserService;


    @PostMapping("/list")
    public ResponseResult getAuthList(@RequestBody AuthDto authDto){
        return apUserRealService.getAuthList(authDto);
    }

    @PostMapping("/authPass")
    public ResponseResult authPass(@RequestBody AuthDto DTO) {
        return apUserRealService.updateStatusById(DTO, AdminConstants.PASS_AUTH);
    }
    @PostMapping("/authFail")
    public ResponseResult authFail(@RequestBody AuthDto DTO) {
        return apUserRealService.updateStatusById(DTO, AdminConstants.FAIL_AUTH);
    }


    @ApiOperation("根据id查询apUser信息")
    @GetMapping("/{id}")
    public ResponseResult<ApUser> findUserById(@PathVariable("id") Integer id) {
        return ResponseResult.okResult(apUserService.getById(id));
    }
}
